home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4516 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.9 KB

  1. Path: bcfreenet.seflin.lib.fl.us!bcfreenet!z007400b
  2. From: z007400b@bcfreenet.seflin.lib.fl.us (Ralph Silverman)
  3. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
  4. Subject: Re: Avoiding typedefs (was: Hungarian notation)
  5. Followup-To: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
  6. Date: 30 Jan 1996 18:52:55 GMT
  7. Organization: SEFLIN Free-Net - Broward
  8. Message-ID: <4elpe7$h9u@bcfreenet.seflin.lib.fl.us>
  9. References: <30C40F77.53B5@swsbbs.com> <4bd <4cc2b2$11jq@navajo.gate.net> <DLM3no.4M6@irvine.com>
  10. NNTP-Posting-Host: bcfreenet.seflin.lib.fl.us
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Adam Beneschan (adam@irvine.com) wrote:
  14. : Douglas Evan Cook <cookd@cs.byu.edu> writes:
  15.  
  16. : > On 21 Jan 1996, Kazimir Kylheku wrote:
  17. : >
  18. : > > I say, don't bother. I avoid typedefs like the plague, even for structures. I
  19. : > > much rather write the longer form.
  20. : > > 
  21. : > >     void myfunction(struct whatever *x);
  22. : > > 
  23. : > > Using excessive typedefs will just occlude your code. What is the point of
  24. : > > having a separate type for MSEC? Later, when someone sees a declaration of a
  25. : > > variable of type MSEC, he will have to go hunting and pecking for the
  26. : > > definition of MSEC. It _obviously_ stands for milliseconds, but what the hell
  27. : > > is it? 
  28.  
  29. : If MSEC obviously stands for milliseconds, then the answer to the
  30. : question "what the heck is it" is "Milliseconds".  If you care at that
  31. : point how "milliseconds" is implemented, you need to go back and
  32. : relearn about "abstraction" and why it's important.
  33.  
  34. : I'll grant that this isn't all that helpful in C, which doesn't
  35. : contain a whole lot of support for abstract data types; so you pretty
  36. : much *do* have to know what type of variable it is if you're going to
  37. : use it.  In C++ or Ada83 or Ada95 or UCSD Pascal or Modula or Eiffel,
  38. : which do provide constructs allow you to define all the operations on
  39. : a type in one place so you don't have to worry about it later, calling
  40. : things by abstract type names without worrying about how they're
  41. : implemented is an absolute MUST.  (By the way, in response to an
  42. : earlier post, THIS is the reason for having named types in those
  43. : languages---NOT lazy compiler implementors.)
  44.  
  45. : > The way I was taught, you use typedefs only for variables that are likely 
  46. : > to change type (and you want to change all of the instances of that type 
  47. : > at once) and for cross-platform portability (in a multi-language 
  48. : > environment like Windows or when you are saving data to disk).  Using it 
  49. : > for most other things will, as you said, only hamper coding and debugging 
  50. : > efforts.  However, to use those examples to induce "typedefs are useless" 
  51. : > is jumping to a bad conclusion.  If you want to argue that the uses that 
  52. : > I gave are bad, we can do that, but to generalize without looking at all 
  53. : > potential uses isn't a good idea.
  54. :  
  55. : I must be missing something.  How does
  56.  
  57. :         void myfunction (Whatever *x);
  58.  
  59. : (where Whatever is a typedef) "occlude your code" or "hamper coding
  60. : and debugging efforts", while
  61.  
  62. :         void myfunction (struct whatever *x);
  63.  
  64. : doesn't?  The second example looks just like the first, in that you're
  65. : declaring a variable using some name that I'd have to go somewhere
  66. : else and look up if I wanted to see how it was implemented.  The only
  67. : difference is a keyword.
  68.  
  69. : Or does the character sequence "struct" have some magical properties
  70. : that cause occlusion to break up and everything to become clear?
  71.  
  72. :                                 -- Adam
  73.  
  74. --
  75. *********begin r.s. response***********
  76.  
  77.     traditionally,
  78.     typedef
  79.     is used to "cut out"
  80.     the names of
  81.     'non-user defined' datatypes
  82.     in source...
  83.  
  84.     the reason,  and justification,
  85.     for this,
  86.     traditional,
  87.     use
  88.     are much the same as with
  89.         #define
  90.     constants
  91.     .
  92.  
  93.  
  94. *********end r.s. response*************
  95. Ralph Silverman
  96. z007400b@bcfreenet.seflin.lib.fl.us
  97.  
  98.